from paddleocr import PaddleOCR

# 初始化OCR模型
ocr_models = {
    'en': PaddleOCR(use_angle_cls=True, lang="en", show_log=False),
    'ch': PaddleOCR(use_angle_cls=True, lang="ch", show_log=False),
    'ar': PaddleOCR(use_angle_cls=True, lang="ar", show_log=False),
    'fr': PaddleOCR(use_angle_cls=True, lang="fr", show_log=False),
    'german': PaddleOCR(use_angle_cls=True, lang="german", show_log=False)
}


def process_ocr(file_path, lang="en"):
    """处理OCR请求"""
    if lang not in ocr_models:
        lang = "en"  # 默认回退到英语

    ocr = ocr_models[lang]
    result = ocr.ocr(file_path, cls=True)
    return result
